//
//  .m
/*
 *  SSPreferenceController
 *  MESLib
 * 
 * Copyright 2003-2009 Starline Software Ltd
 * 
 * This file is part of MESLib.
 * 
 * MESLib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MESLib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with MESLib. If not, see <http://www.gnu.org/licenses/>.
 */
//  Created by Tobias Haughton on Sat Feb 08 2003.
//
//SSPreferenceController handles all of the user preferences saving them to the user defaults

#import "SSPreferenceController.h"


@implementation SSPreferenceController

- (id)init {
   self = [super initWithWindowNibName:@"PreferencePanel"];
   if (self) {
   }
   return self;
}

- (void)awakeFromNib
{
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
   
   //set the state of our checkboxes
   [[eventDisplayMatrix cellWithTag:preferenceShowSourceFieldTag] setState:[defaults boolForKey:SSDisplayEBSourceKey]];
   [[eventDisplayMatrix cellWithTag:preferenceShowObjectFieldTag] setState:[defaults boolForKey:SSDisplayEBObjectKey]];
   [[eventDisplayMatrix cellWithTag:preferenceShowLocationFieldTag] setState:[defaults boolForKey:SSDisplayEBLocationKey]];
   [[eventDisplayMatrix cellWithTag:preferenceShowBeginDateFieldTag] setState:[defaults boolForKey:SSDisplayEBBeginDateKey]];
   [[eventDisplayMatrix cellWithTag:preferenceShowEndDateFieldTag] setState:[defaults boolForKey:SSDisplayEBEndDateKey]];
   [[eventDisplayMatrix cellWithTag:preferenceShowActorFieldTag] setState:[defaults boolForKey:SSDisplayEBActorKey]];

   [dateRowDisplayMatrix selectCellWithTag:[defaults integerForKey:SSDateDisplayKey]];

   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayActorColumnTag] setState:[defaults boolForKey:SSEBTableActorColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayActionColumnTag] setState:[defaults boolForKey:SSEBTableActionColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayObjectColumnTag] setState:[defaults boolForKey:SSEBTableObjectColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayLocationColumnTag] setState:[defaults boolForKey:SSEBTableLocationColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplaySourceColumnTag] setState:[defaults boolForKey:SSEBTableSourceColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayRemarkColumnTag] setState:[defaults boolForKey:SSEBTableRemarkColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayBeginDateColumnTag] setState:[defaults boolForKey:SSEBTableBegindateColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayEndDateColumnTag] setState:[defaults boolForKey:SSEBTableEnddateColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayBeginTimeColumnTag] setState:[defaults boolForKey:SSEBTableBegintimeColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayEndTimeColumnTag] setState:[defaults boolForKey:SSEBTableEndtimeColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayXPosColumnTag] setState:[defaults boolForKey:SSEBTableXpositionColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayLabelColumnTag] setState:[defaults boolForKey:SSEBTableLabelColumnKey]];
   [[ebTableDisplayMatrix cellWithTag:preferenceETDisplayDurationColumnTag] setState:[defaults boolForKey:SSEBTableDurationColumnKey]];

   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayNumberColumnTag] setState:[defaults boolForKey:SSDiamondTableNumberColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayTypeColumnTag] setState:[defaults boolForKey:SSDiamondTableOwnertypeColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayOriginColumnTag] setState:[defaults boolForKey:SSDiamondTableOwnerdescriptionColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayAnalystColumnTag] setState:[defaults boolForKey:SSDiamondTableAnalystColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayFileIDColumnTag] setState:[defaults boolForKey:SSDiamondTableFileidColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayDescriptionColumnTag] setState:[defaults boolForKey:SSDiamondTableDescriptionColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayStateColumnTag] setState:[defaults boolForKey:SSDiamondTableDiamondstateColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayUdvalue1ColumnTag] setState:[defaults boolForKey:SSDiamondTableUdvalue1ColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayUdvalue2ColumnTag] setState:[defaults boolForKey:SSDiamondTableUdvalue2ColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayUdvalue3ColumnTag] setState:[defaults boolForKey:SSDiamondTableUdvalue3ColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayUdvalue4ColumnTag] setState:[defaults boolForKey:SSDiamondTableUdvalue4ColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayUdvalue5ColumnTag] setState:[defaults boolForKey:SSDiamondTableUdvalue5ColumnKey]];
   [[diamondTableDisplayMatrix cellWithTag:preferenceDTDisplayUdvalue6ColumnTag] setState:[defaults boolForKey:SSDiamondTableUdvalue6ColumnKey]];

   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayOptionColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableOptionColumnKey]];
   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayUdvalue1ColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableUdvalue1ColumnKey]];
   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayUdvalue2ColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableUdvalue2ColumnKey]];
   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayUdvalue3ColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableUdvalue3ColumnKey]];
   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayUdvalue4ColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableUdvalue4ColumnKey]];
   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayUdvalue5ColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableUdvalue5ColumnKey]];
   [[diamondOptionTableDisplayMatrix cellWithTag:preferenceDOTDisplayNumberColumnTag] setState:[defaults boolForKey:SSDiamondOptionTableIndexColumnKey]];

   [[diamondTradeoffTableDisplayMatrix cellWithTag:preferenceDTTDisplayUdvalue1ColumnTag] setState:[defaults boolForKey:SSDiamondTradeoffTableUdvalue1ColumnKey]];
   [[diamondTradeoffTableDisplayMatrix cellWithTag:preferenceDTTDisplayUdvalue2ColumnTag] setState:[defaults boolForKey:SSDiamondTradeoffTableUdvalue2ColumnKey]];
   [[diamondTradeoffTableDisplayMatrix cellWithTag:preferenceDTTDisplayUdvalue3ColumnTag] setState:[defaults boolForKey:SSDiamondTradeoffTableUdvalue3ColumnKey]];
   [[diamondTradeoffTableDisplayMatrix cellWithTag:preferenceDTTDisplayProColumnTag] setState:[defaults boolForKey:SSDiamondTradeoffTableProColumnKey]];
   [[diamondTradeoffTableDisplayMatrix cellWithTag:preferenceDTTDisplayConColumnTag] setState:[defaults boolForKey:SSDiamondTradeoffTableConColumnKey]];
   [[diamondTradeoffTableDisplayMatrix cellWithTag:preferenceDTTDisplayNumberColumnTag] setState:[defaults boolForKey:SSDiamondTradeoffTableIndexColumnKey]];


   [[commentTableDisplayMatrix cellWithTag:preferenceCTDisplayCommentColumnTag] setState:[defaults boolForKey:SSCommentTableCommentstringColumnKey]];
   [[commentTableDisplayMatrix cellWithTag:preferenceCTDisplayXPositionColumnTag] setState:[defaults boolForKey:SSCommentTableXpositionColumnKey]];
   [[commentTableDisplayMatrix cellWithTag:preferenceCTDisplayYPositionColumnTag] setState:[defaults boolForKey:SSCommentTableYpositionColumnKey]];
   [[commentTableDisplayMatrix cellWithTag:preferenceCTDisplayTypeColumnTag] setState:[defaults boolForKey:SSCommentTableTypeColumnKey]];
   
   [startupOptionMatrix selectCellWithTag:[defaults integerForKey:SSStartupOptionKey]];

   [saveBackupCheckBox setState:[defaults boolForKey:SSSaveBackupKey]];
   [saveBackupField setIntValue:[defaults integerForKey:SSSaveBackupFrequencyKey]];
   [saveBackupField setEnabled:[defaults boolForKey:SSSaveBackupKey]];

   [dupeWarningCheckBox setState:[defaults boolForKey:SSDisplayDupeWarningKey]];
}

- (IBAction)changeEventDisplay:(id)sender
{
   //workout which cell has been changed, set the value in the user defaults and send a notification so that the ebs will update their display 
   switch([[sender selectedCell] tag]) {
      case preferenceShowSourceFieldTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                forKey:SSDisplayEBSourceKey];

         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSPrepareForUpdateEBDisplay"
                                                             object:nil];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSUpdateEBDisplay"
                                                             object:[sender selectedCell]];
            
         break;
      case preferenceShowObjectFieldTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                forKey:SSDisplayEBObjectKey];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSPrepareForUpdateEBDisplay"
                                                             object:nil];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSUpdateEBDisplay"
                                                             object:[sender selectedCell]];
           break;
      case preferenceShowLocationFieldTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                  forKey:SSDisplayEBLocationKey];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSPrepareForUpdateEBDisplay"
                                                             object:nil];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSUpdateEBDisplay"
                                                             object:[sender selectedCell]];
           break;
      case preferenceShowBeginDateFieldTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                   forKey:SSDisplayEBBeginDateKey];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSPrepareForUpdateEBDisplay"
                                                             object:nil];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSUpdateEBDisplay"
                                                             object:[sender selectedCell]];
           break;
      case preferenceShowEndDateFieldTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                 forKey:SSDisplayEBEndDateKey];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSPrepareForUpdateEBDisplay"
                                                             object:nil];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSUpdateEBDisplay"
                                                             object:[sender selectedCell]];
         break;
      case preferenceShowActorFieldTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                 forKey:SSDisplayEBActorKey];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSPrepareForUpdateEBDisplay"
                                                             object:nil];
         [[NSNotificationCenter defaultCenter] postNotificationName:@"SSUpdateEBDisplay"
                                                             object:[sender selectedCell]];
         break;
      default:
         break;
   }
}

- (IBAction)changeDateRowDisplay:(id)sender
{
   [[NSUserDefaults standardUserDefaults] setInteger:[[sender selectedCell] tag]
                                           forKey:SSDateDisplayKey];

   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSDateRowDisplayChanged"
                                                       object:nil];
}

- (IBAction)changeEBTableColumnDisplay:(id)sender
{
   switch([[sender selectedCell] tag]) {
      case preferenceETDisplayActorColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableActorColumnKey];
         break;
      case preferenceETDisplayActionColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableActionColumnKey];
         break;
      case preferenceETDisplayObjectColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableObjectColumnKey];
           break;
      case preferenceETDisplayLocationColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableLocationColumnKey];
           break;
      case preferenceETDisplaySourceColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableSourceColumnKey];
         break;
      case preferenceETDisplayRemarkColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableRemarkColumnKey];
         break;
      case preferenceETDisplayBeginDateColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableBegindateColumnKey];
         break;
      case preferenceETDisplayEndDateColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableEnddateColumnKey];
         break;
      case preferenceETDisplayBeginTimeColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSEBTableBegintimeColumnKey];
         break;
      case preferenceETDisplayEndTimeColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                       forKey:SSEBTableEndtimeColumnKey];
         break;
      case preferenceETDisplayXPosColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableXpositionColumnKey];
         break;
      case preferenceETDisplayLabelColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                       forKey:SSEBTableLabelColumnKey];
         break;
      case preferenceETDisplayDurationColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                     forKey:SSEBTableDurationColumnKey];
         break;
      default:
         break;
   }

   //send a note so that the panel will update
   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSEBTableDisplayChanged"
                                                       object:[sender selectedCell]];
}

- (IBAction)changeDiamondTableColumnDisplay:(id)sender
{
   switch([[sender selectedCell] tag]) {
      case preferenceDTDisplayNumberColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                     forKey:SSDiamondTableNumberColumnKey];
         break;
      case preferenceDTDisplayTypeColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                      forKey:SSDiamondTableOwnertypeColumnKey];
         break;
      case preferenceDTDisplayOriginColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                      forKey:SSDiamondTableOwnerdescriptionColumnKey];
         break;
      case preferenceDTDisplayAnalystColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondTableAnalystColumnKey];
         break;
      case preferenceDTDisplayFileIDColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                      forKey:SSDiamondTableFileidColumnKey];
         break;
      case preferenceDTDisplayDescriptionColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                      forKey:SSDiamondTableDescriptionColumnKey];
         break;
      case preferenceDTDisplayStateColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTableDiamondstateColumnKey];
         break;
      case preferenceDTDisplayUdvalue1ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                     forKey:SSDiamondTableUdvalue1ColumnKey];
         break;
      case preferenceDTDisplayUdvalue2ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondTableUdvalue2ColumnKey];
         break;
      case preferenceDTDisplayUdvalue3ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondTableUdvalue3ColumnKey];
         break;
      case preferenceDTDisplayUdvalue4ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondTableUdvalue4ColumnKey];
         break;
      case preferenceDTDisplayUdvalue5ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondTableUdvalue5ColumnKey];
         break;
      case preferenceDTDisplayUdvalue6ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondTableUdvalue6ColumnKey];
         break;
      default:
         break;
   }

   //send a note so that the panel will update
   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSDiamondTableDisplayChanged"
                                                       object:[sender selectedCell]];
}

- (IBAction)changeDiamondOptionTableColumnDisplay:(id)sender
{
   switch([[sender selectedCell] tag]) {
      case preferenceDOTDisplayOptionColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondOptionTableOptionColumnKey];
         break;
      case preferenceDOTDisplayUdvalue1ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondOptionTableUdvalue1ColumnKey];
         break;
      case preferenceDOTDisplayUdvalue2ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondOptionTableUdvalue2ColumnKey];
         break;
      case preferenceDOTDisplayUdvalue3ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondOptionTableUdvalue3ColumnKey];
         break;
      case preferenceDOTDisplayUdvalue4ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondOptionTableUdvalue4ColumnKey];
         break;
      case preferenceDOTDisplayUdvalue5ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                        forKey:SSDiamondOptionTableUdvalue5ColumnKey];
         break;
      case preferenceDOTDisplayNumberColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondOptionTableIndexColumnKey];
         break;
      default:
         break;
   }

   //send a note so that the panel will update
   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSDiamondOptionTableDisplayChanged"
                                                       object:[sender selectedCell]];
}

- (IBAction)changeDiamondTradeoffTableColumnDisplay:(id)sender
{
   switch([[sender selectedCell] tag]) {
      case preferenceDTTDisplayUdvalue1ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTradeoffTableUdvalue1ColumnKey];
         break;
      case preferenceDTTDisplayUdvalue2ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTradeoffTableUdvalue2ColumnKey];
         break;
      case preferenceDTTDisplayUdvalue3ColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTradeoffTableUdvalue3ColumnKey];
         break;
      case preferenceDTTDisplayProColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTradeoffTableProColumnKey];
         break;
      case preferenceDTTDisplayConColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTradeoffTableConColumnKey];
         break;
      case preferenceDTTDisplayNumberColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                         forKey:SSDiamondTradeoffTableIndexColumnKey];
         break;
      default:
         break;
   }

   //send a note so that the panel will update
   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSDiamondTradeoffTableDisplayChanged"
                                                       object:[sender selectedCell]];
}

- (IBAction)changeCommentTableColumnDisplay:(id)sender
{
   switch([[sender selectedCell] tag]) {
      case preferenceCTDisplayCommentColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                      forKey:SSCommentTableCommentstringColumnKey];
         break;
      case preferenceCTDisplayXPositionColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                    forKey:SSCommentTableXpositionColumnKey];
         break;
      case preferenceCTDisplayYPositionColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                      forKey:SSCommentTableYpositionColumnKey];
         break;
      case preferenceCTDisplayTypeColumnTag:[[NSUserDefaults standardUserDefaults] setBool:[[sender selectedCell]  state]
                                                                                       forKey:SSCommentTableTypeColumnKey];
         break;
      default:
         break;
   }
   
   //send a note so that the panel will update
   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSCommentTableDisplayChanged"
                                                       object:[sender selectedCell]];
}

- (IBAction)startUpOptionChanged:(id)sender
{
   [[NSUserDefaults standardUserDefaults] setInteger:[[sender selectedCell]  tag]
                                              forKey:SSStartupOptionKey];
}

- (IBAction)changeSaveBackup:(id)sender
{
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

   [defaults setBool:[sender state]
              forKey:SSSaveBackupKey];

   [saveBackupField setEnabled:[sender state]]; //set the state of the frequency field based on the users selection

   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSSaveBackupChanged"
                                                       object:nil];
}

- (IBAction)changeSaveBackupFrequency:(id)sender
{
   [[NSUserDefaults standardUserDefaults] setInteger:[sender intValue]
                                              forKey:SSSaveBackupFrequencyKey];
   
   [[NSNotificationCenter defaultCenter] postNotificationName:@"SSSaveBackupChanged"
                                                       object:nil];
}

- (IBAction)changeDupeWarning:(id)sender
{
   [[NSUserDefaults standardUserDefaults] setBool:[sender state]
              forKey:SSDisplayDupeWarningKey];
   
}

@end
